<template>
  <div class="commentitems">
    <div class="commentitem" v-for="(item,index) in commentchild" :key="index">
      <div class="userimg">
        <img v-if="item.userinfo && item.userinfo.user_img" :src="item.userinfo.user_img">
        <img src="@/assets/head.png" v-else>
        <p>
          <span v-if="item.userinfo">{{item.userinfo.name}}</span>
          <span>{{item.comment_date}}</span>
        </p>
      </div>
      <div class="commentcontent">
        <div v-if="!temp">
          {{item.comment_content}}  <span class="publish" @click="Postitemcomment(item.comment_id)">回复</span>
        </div>
        <div v-else>
          回复<span style="color: #478ef0">{{item.parent_user_info.name}}</span>:
          {{item.comment_content}}<span class="publish"  @click="Postitemcomment(item.comment_id)">回复</span>
        </div>
      </div>
      <commentitemchild :commentchild="item.child" @postChild="postchild" :temp="true"></commentitemchild>
    </div>
  </div>
</template>

<script>
export default {
  name: "commentitemchild",
  props:['commentchild','temp'],
  methods:{
    Postitemcomment(id){
      this.$emit('postChild',id)
      this.$emit('PostPublish',id)
    },
    postchild(id){
      this.Postitemcomment(id)
      this.$emit('PostPublish',id)
    }
  }
}
</script>

<style scoped lang="less">
.commentitems {
  .commentitem {
    padding: 1.78vw 0;
    display: flex;
    flex-direction: column;
    .userimg {
      margin-right: 2.78vw;
      display: flex;
      img {
        width: 9.72vw;
        height: 9.72vw;
        border-radius: 50%;
        margin: 0 1.39vw 2.78vw 0;
      }
      p{
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 3.61vw;
        color: #666666;
        margin-bottom: 1.39vw;

      }
    }
    .commentcontent{
      position: relative;
      flex: 1;
      div{
        font-size: 3.61vw;
        margin-left: 11.11vw;
      }
      .publish{
        color: #fb7299;
        position: absolute;
        right: 4.17vw;
      }
    }
  }
}
</style>
